﻿using System.Collections.Generic;
using System.Linq;
using Atha.Contracts;

namespace Atha.Extensions
{
	namespace TestRunResults
	{
		using TestRunTestResults;

		public static class TestRunResultExtensions
		{
			public static bool AllSucceeded(this IEnumerable<ITestRunResult> testRunResults)
			{
				return testRunResults.SelectMany(r => r.Tests).All(test => test.Succeeded());
			}

			public static bool AllFailed(this IEnumerable<ITestRunResult> testRunResults)
			{
				return testRunResults.SelectMany(r => r.Tests).All(test => test.Failed());
			}

			public static bool HasError(this IEnumerable<ITestRunResult> testRunResults)
			{
				return testRunResults.SelectMany(r => r.Tests).Any(test => test.IsError());
			}

			public static bool Has(this IEnumerable<ITestRunResult> testRunResults, ITestRunTestResultStatus testRunTestResultStatus)
			{
				return testRunResults.All(test => test.Has(testRunTestResultStatus));
			}

			public static bool AllSucceeded(this ITestRunResult testRunResult)
			{
				return testRunResult.Tests.All(test => test.Succeeded());
			}

			public static bool AllFailed(this ITestRunResult testRunResult)
			{
				return testRunResult.Tests.All(test => test.Failed());
			}

			public static bool HasError(this ITestRunResult testRunResult)
			{
				return testRunResult.Tests.Any(test => test.IsError());
			}

			public static bool Has(this ITestRunResult testRunResult, ITestRunTestResultStatus testRunTestResultStatus)
			{
				return testRunResult.Tests.Any(test => test.Has(testRunTestResultStatus));
			}
		}
	}
}